package com.ayoka.ui.training;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.ayoka.R;
import com.ayoka.adapter.TrainingQuestionOptionMultiAdapter;
import com.ayoka.base.BaseRecyclerViewFragment;
import com.ayoka.databinding.FragmentTrainingPrepareBinding;
import com.ayoka.mvp.TrainingDetailMVP.TrainingDetailModel.TrainingQuestionBean;
import com.ayoka.mvp.TrainingPrepareMVP.ITrainingPrepareView;
import com.ayoka.mvp.TrainingPrepareMVP.TrainingPrepareModel.TrainingQuestionMultiEntity;
import com.ayoka.mvp.TrainingPrepareMVP.TrainingPreparePresenter;
import com.jcp.baselibrary.brvah.BaseQuickAdapter;
import com.jcp.baselibrary.brvah.BaseViewHolder;

import java.util.List;

/**
 * Created by 150817 on 2016/7/25.
 */
public class TrainingPrepareFragment extends BaseRecyclerViewFragment<TrainingQuestionMultiEntity,  FragmentTrainingPrepareBinding, TrainingPreparePresenter> implements ITrainingPrepareView {

    public static TrainingPrepareFragment newInstance(TrainingQuestionBean trainingQuestionBean) {
        TrainingPrepareFragment trainingPrepareFragment = new TrainingPrepareFragment();
        Bundle bundle = new Bundle();
        bundle.putSerializable("TrainingQuestionBean", trainingQuestionBean);
        trainingPrepareFragment.setArguments(bundle);
        return trainingPrepareFragment;
    }

    private TrainingQuestionBean trainingQuestionBean;

    @Override
    protected void configBundleArguments() {
        Bundle bundle = getArguments();
        if (bundle != null) {
            trainingQuestionBean = (TrainingQuestionBean) bundle.getSerializable("TrainingQuestionBean");
        }
    }

    @Override
    public int getContentLayout() {
        return R.layout.fragment_training_prepare;
    }

    @Override
    protected SwipeRefreshLayout getRefreshLayout() {
        return null;
    }

    @Override
    protected RecyclerView getRecyclerView() {
        return mDataBinding.recyclerView;
    }

    @NonNull
    @Override
    protected BaseQuickAdapter<TrainingQuestionMultiEntity, ? extends BaseViewHolder> getAdapter() {
        TrainingQuestionOptionMultiAdapter adapter = new TrainingQuestionOptionMultiAdapter();
        adapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
            @Override
            public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                TrainingQuestionMultiEntity questionMultiEntity = (TrainingQuestionMultiEntity) adapter.getItem(position);
                if (questionMultiEntity.getItemType() == TrainingQuestionMultiEntity.BUTTON){
                    ((TrainingPrepareActivity)getActivity()).showNextQuestionFragment();
                }
            }
        });
        return adapter;
    }

    @Override
    protected RecyclerView.ItemDecoration getRecycleDivider() {
        return null;
    }

    @Override
    protected void getData(boolean isShowWaitDialog) {
    }

    @Override
    protected void initData() {
        mPresenter.formatQuestion(trainingQuestionBean);
    }

    @Override
    protected TrainingPreparePresenter getPresenter() {
        return new TrainingPreparePresenter();
    }

    @Override
    public void configTrainingQuestion(List<TrainingQuestionMultiEntity> listData) {
        setLoadMoreLayout(listData, 1);
    }
}
